using System;
using AGG;
using AGG.VertexSource;
using AGG.Transform;
using AGG.UI;
using Reflexive.Math;
using Reflexive.Game;

namespace RockBlaster
{
	public class BulletStyleSheet : GameObject
	{
		[GameDataNumberAttribute("TurnRate")]
		public double TurnRate = 4;
		[GameDataNumberAttribute("Ship Thrust")]
		public double ThrustAcceleration = 10;
		[GameDataNumberAttribute("Friction")]
		public double Friction = .99;
		[GameDataNumberAttribute("DamageOnCollide")]
		public double DamageOnCollide = 10;
		[GameDataNumberAttribute("NumSecondsToLive")]
		public double NumSecondsToLive = 2;
	}

	/// <summary>
	/// Description of Player.
	/// </summary>
	public class Bullet : Entity
	{
		//[GameDataFromAssetTree("StyleSheet")];
		protected BulletStyleSheet m_BulletStyleSheet;
		
		protected Ellipse m_Shape;
		double m_NumSocendsUpdated;
		
		[GameDataNumberAttribute("Rotation")] // This is for save game
		protected double m_Rotation;
		
		public Bullet(Vector2D position, Vector2D Velocity)
			: base(3)
		{
			Position = position;
			m_Shape = new Ellipse(0, 0, 3, 3);
			m_Velocity = Velocity;
			
			m_BulletStyleSheet = new BulletStyleSheet();
		}

        protected override void DoDraw(Graphics2D destRenderer)
		{
            Affine Final = Affine.NewIdentity();
            Final *= Affine.NewRotation(m_Rotation);
            Final *= Affine.NewTranslation(m_Position.x, m_Position.y);
			VertexSourceApplyTransform TransformedShip = new VertexSourceApplyTransform(m_Shape, Final);
            destRenderer.Render(TransformedShip, new RGBA_Bytes(.9, .4, .2, 1)); 
		}

		public override void Update(double numSecondsPassed)
		{
			base.Update(numSecondsPassed);
			m_NumSocendsUpdated += numSecondsPassed;
			if(m_NumSocendsUpdated > m_BulletStyleSheet.NumSecondsToLive)
			{
				this.TakeDamage(MaxDamage, null);
			}
		}
		
		public override double GiveDamage()
		{
			this.TakeDamage(MaxDamage, null);
			return m_BulletStyleSheet.DamageOnCollide;
		}
	}
}
